package com.demo.money.controller.costdetails;

import com.demo.money.model.Costdetails;
import com.demo.money.kit.example.CostdetailsExample;
import com.demo.money.model.User;
import com.demo.money.service.CostdetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * CostdetailsIndexListHtml类<br>
 * costdetails/indexList.html页面里的请求映射关系
 * <p>
 * <b>常用方法</b>：<br>
 * 1.deleteCostdetailsByKey - 删除一条消费信息
 * .goToAddNokey - 跳转到costdetailsAddNokey.html页面
 * .goToCostdetailsEditByKey - 跳转到costdetailsEditByKey.html页面
 * .selectAllByValid - 查询全部支出数据
 * .selectByExample - 条件查询
 * <p>
 * <b>私有方法</b>：<br>
 * 1.方法名 - 方法说明
 * <p>
 * <b>全类名</b>:com.demo.money.controller<br>
 * <b>类名</b>:CostdetailsIndexListHtml<br>
 * <b>创建者</b>:张峰浦<br>
 * <b>创建时间</b>:2020/3/15 17:57<br>
 */
@Controller
public class CostdetailsIndexListHtml {

    @Autowired
    private CostdetailsService costdetailsService;

    /**
     * 删除一条消费信息
     *
     * @return 响应页面地址
     */
    @RequestMapping({"deleteCostdetailsByKey"})
    public String deleteCostdetailsByKey(@RequestParam("id") Integer id) {

        costdetailsService.deleteByPrimaryKey(id);

        return "costdetails/indexList";

    }

    /**
     * 跳转到costdetailsEditByKey.html页面
     *
     * @param id    主键id
     * @param model 消息存储组件
     * @return 响应页面地址
     */
    @RequestMapping({"goToCostdetailsEditByKey"})
    public String goToCostdetailsEditByKey(@RequestParam("id") Integer id, Model model) {

        CostdetailsExample costdetailsExample = new CostdetailsExample();

        CostdetailsExample.Criteria criteria = costdetailsExample.createCriteria();

        criteria.andIdEqualTo(id);

        Costdetails costdetails = costdetailsService.selectByExample(costdetailsExample).get(0);

        model.addAttribute("oneCostdetails", costdetails);

        return "costdetails/costdetailsEditByKey";

    }

    /**
     * 跳转到costdetailsAddNokey.html页面
     *
     * @return 响应页面地址
     */
    @RequestMapping({"goToCostdetailsAddNokey"})
    public String goToAddNokey() {

        return "costdetails/costdetailsAddNokey";

    }


    /**
     * 跳转到支出明细页面
     *
     * @return 响应页面地址
     */
    @RequestMapping({"costdetailsIndexList"})
    public String selectAllByValid() {
        return "costdetails/indexList";
    }



}
